/*
 * Licensed to the Apache Software Foundation (ASF) under one
 * or more contributor license agreements.  See the NOTICE file
 * distributed with this work for additional information
 * regarding copyright ownership.  The ASF licenses this file
 * to you under the Apache License, Version 2.0 (the
 * "License"); you may not use this file except in compliance
 * with the License.  You may obtain a copy of the License at
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing,
 * software distributed under the License is distributed on an
 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
 * KIND, either express or implied.  See the License for the
 * specific language governing permissions and limitations
 * under the License.
 */
package com.google.code.twiddling.core.io.text;

import java.io.PrintStream;
import java.util.HashMap;

/**
 * 
 * @author <a href="mailto:howard.gao@gmail.com">Howard Gao</a> 
 *
 */
public class TextObjectFactory {

	private static HashMap<String, TableSchema> schemas = new HashMap<String, TableSchema>();
	
	static {
		loadPredefinedTableSchemas();
	}
	
	public static TextTable getTable(String schemaName) {
		TextTable table = null;
		TableSchema schema = schemas.get(schemaName);
		if (schema != null) {
			//schema.cleanHeaders();
			table = schema.newTable();
		}
		return table;
	}

	private static void loadPredefinedTableSchemas() {
		loadDefaultSchema();
		loadCommandHelpSchema();
	}

	private static void loadDefaultSchema() {
		TableSchema defaultSchema = new TableSchema("default");
		schemas.put("default", defaultSchema);
	}

	/**
	 * this schema is for displaying help info
	 * The title is left aligned.
	 * The table has three columns, options, long options and description.
	 * The table header is hidden.
	 * The table has no column separators
	 */
	private static void loadCommandHelpSchema() {
		TableSchema helpSchema = new TableSchema("help");
		helpSchema.setShowHeaders(false);
		helpSchema.addColumns(new String[] { "options", "long options", "description" });
		helpSchema.setColumnWidth("options", 8, null);
		helpSchema.setColumnWidth("long options", 14, null);
		helpSchema.setColumnSep("");
		schemas.put("help", helpSchema);
	}
}
